﻿// ┌────────────────────────────────────────────────
// │  control class :: requirement                          
// │  1 :: rms.core.js
// │  2 :: 
// │  3 :: 
// │  4 :: 
// │  5 ::
// └────────────────────────────────────────────────
//=====================================================================================================
// Class Base Control Contructor
//=====================================================================================================
(function (RMS) {
    function BaseControl(settings) {
        this.init(settings);
    };

    BaseControl.prototype.extend = function () {
        var baseClass = this.constructor;
        function Control() {
            baseClass.apply(this, arguments);
        }

        function inherit(Child, Parent) {
            function Bridge() { };

            Bridge.prototype = Parent.prototype;
            Child.prototype = new Bridge();
            Child.prototype.constructor = Child;
            return Child;
        };

        return inherit(Control, baseClass);
    };

    BaseControl.prototype.init = function () {
        throw Error('BaseControl init() method unimplemented');
    };

    BaseControl.prototype.load = function () {
        throw Error('BaseControl load() method unimplemented');
    };

    BaseControl.prototype.getInstance = function () {
        throw Error('BaseControl getInstance() method unimplemented');
    };

    BaseControl.prototype.updateSettings = function () {
        throw Error('BaseControl updateSettings() method unimplemented');
    };

    BaseControl.prototype.getSettings = function () {
        throw Error('BaseControl getSettings() method unimplemented');
    };

    BaseControl.prototype.isCompleted = false;

    BaseControl.prototype.loadComplete = function () {
        throw Error('BaseControl loadComplete() method unimplemented');
    };

    //something here: enable/disable,...

    RMS.BaseControl = BaseControl;
})(RMS);
//=====================================================================================================
//Control class constructor
//=====================================================================================================
(function (RMS) {
    var Control = RMS.BaseControl.prototype.extend();

    Control.prototype.init = function (settings) {
        this.settings = updateSettingsByType(settings);
        //console.log('::control::init::', this.settings);
        var currSetting = $.extend(true, {}, this.settings);
        //delete properties redundancy
        delete currSetting.controlType;
        delete currSetting.id;
        delete currSetting.callback;
        delete currSetting.url;                        
        delete currSetting.action;
                      
        this.instance = $(this.settings.id).factory(currSetting);
        this.loadComplete(this.instance);
    };

    Control.prototype.loadComplete = function (instance) {
        this.isCompleted = true;
        if (this.settings.callback) {
            this.settings.callback(instance);
        }
    };

    Control.prototype.getInstance = function () {
        return this.instance;
    };

    Control.prototype.getSettings = function () {
        return this.settings;
    };

    Control.prototype.updateSettings = function (settings) {
        if (settings) {
            this.settings = $.extend(true, this.settings, settings);
        }
    };

    //private function
    function updateSettingsByType(settings) {
        if (settings.id.indexOf('#') == -1 && settings.id.indexOf('.') == -1) {
            settings.id = '#' + settings.id;
        }
        var source, i;
        switch (settings.controlType.toString()) {
            //=============input==================//                                                                                                                                                                                   
            case '1':   //input
                settings.jqxType = 'jqxInput';
                break;
            case '2': //input multi select
                settings.jqxType = 'jqxInput';
                source = settings.source;

                settings.source = function (query, response) {
                    var item = query.split(/,\s*/).pop();
                    // update the search query.
                    $(settings.id).jqxInput({ query: item });
                    response(source);
                };
                settings.renderer = function (itemValue, inputValue) {
                    var terms = inputValue.split(/,\s*/);
                    // remove the current input
                    terms.pop();
                    // add the selected item
                    terms.push(itemValue);
                    // add placeholder to get the comma-and-space at the end
                    terms.push("");
                    return terms.join(", ");
                };
                break;
            case '3': //AutoComplete
                settings.jqxType = 'jqxInput';
                break;
            case '4':
                settings.jqxType = 'jqxNumberInput';
                break;
            case '5':
                settings.jqxType = 'jqxMaskedInput';
                break;
            case '6':
                break;
            case '7':
                break;
            case '8':
                break;
            case '9':
                break;
            case '10':
                break;
            //============datetime===================//                                                                                                                                                                                      
            case '11': //datetime
                settings.jqxType = 'jqxDateTimeInput';
                settings.animationType = 'slide';
                break;
            case '12': //time
                settings.formatString = 'T';
                settings.showCalendarButton = false;
                settings.jqxType = 'jqxDateTimeInput';
                break;
            case '13': //calendar
                settings.jqxType = 'jqxCalendar';
                break;
            case '14':
                break;
            case '15':
                break;
            case '16':
                break;
            case '17':
                break;
            case '18':
                break;
            case '19':
                break;
            case '20':
                break;
            //===============combobox================//                                                                                                                                                                                               
            case '21': //combobox
                settings.jqxType = 'jqxComboBox';
                if (typeof settings.valueMember == 'undefined') {
                    settings.valueMember = "ID";
                    settings.displayMember = "Name";
                }
                if (settings.source) {
                    source = settings.source;
                    if (typeof source == 'object') {
                        if (settings.multiSelect) {
                            settings.callback = function (instance) {
                                for (i = 0; i < source.length; i++) {
                                    if (RMS.pub.convertBool(source[i].DefaultValue)) {
                                        instance.jqxComboBox('selectItem', source[i][settings.valueMember]);
                                    }
                                }
                            };
                        }
                        else if (settings.checkboxes) {
                            settings.callback = function (instance) {
                                for (i = 0; i < source.length; i++) {
                                    if (RMS.pub.convertBool(source[i].DefaultValue)) {
                                        instance.jqxComboBox('checkItem', source[i][settings.valueMember]);
                                    }
                                }
                            };
                        }
                        else {
                            for (i = 0; i < source.length; i++) {
                                if (RMS.pub.convertBool(source[i].DefaultValue)) {
                                    settings.selectedIndex = i;
                                    break;
                                }
                            }
                        }
                    }
                }
                break;
            case '22': //combobox ajax only
                settings.jqxType = 'jqxComboBox';
                if (settings.source) {
                    source = settings.source;
                    if (typeof settings.valueMember == 'undefined') {
                        settings.valueMember = "ID";
                        settings.displayMember = "Name";
                    }
                    settings.source = new $.jqx.dataAdapter(source, {
                        loadServerData: function (serverdata, source, callback) {
                            RMS.Ajax({
                                url: source.url,
                                type: 'post',
                                success: function (data) {
                                    var responeData = [];
                                    if (data) {
                                        responeData = new RMS.CCSV2JSON(data).toJson();
                                        if (responeData && responeData[1]) {
                                            responeData = responeData[1];
                                        }
                                    }
                                    callback({ records: responeData });
                                }
                            });
                        },
                        loadComplete: function (data) {
                            //waiting control init success
                            window.setTimeout(function () {
                                settings.callback(data);
                            }, 10);
                        }
                    });

                    settings.callback = function (data) {
                        if (data.records) {
                            if (settings.multiSelect) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('selectItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else if (settings.checkboxes) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('checkItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        settings.selectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    };
                }
                break;
            case '23':
                settings.jqxType = 'jqxComboBox';
                if (settings.source) {
                    source = settings.source;
                    var asource = [];  //getSelectedItem
                    for (i = 0; i < source.length; i++) {
                        asource.push({
                            html: RMS.pub.string.Format("<div tabIndex=0 style='padding: 1px;'>{0}</div>", source[i].Name),
                            label: source[i].Name,
                            group: source[i].Group,
                            id: source[i].ID
                        });
                    }
                    if (asource.length) {
                        settings.source = asource;
                    }
                }
                break;
            case '24':
                settings.jqxType = 'jqxComboBox';
                break;
            //===============Dropdownlist================//   
            case '25':
                settings.jqxType = 'jqxDropDownList';
                if (typeof settings.valueMember == 'undefined') {
                    settings.valueMember = "ID";
                    settings.displayMember = "Name";
                }
                break;
            case '26':
                settings.jqxType = 'jqxDropDownList';
                if (typeof settings.valueMember == 'undefined') {
                    settings.valueMember = "ID";
                    settings.displayMember = "Name";
                }
                if (settings.source) {
                    source = settings.source;
                    settings.source = new $.jqx.dataAdapter(source, {
                        loadServerData: function (serverdata, source, callback) {
                            RMS.Ajax({
                                url: source.url,
                                type: 'post',
                                success: function (data) {
                                    var responeData = [];
                                    if (data) {
                                        responeData = new RMS.CCSV2JSON(data).toJson();
                                        if (responeData && responeData[1]) {
                                            responeData = responeData[1];
                                        }
                                    }
                                    callback({ records: responeData });
                                }
                            });
                        },
                        loadComplete: function (data) {
                            window.setTimeout(function () {
                                settings.callback(data);
                            }, 10);
                        }
                    });

                    settings.callback = function (data) {
                        if (data.records) {
                            if (settings.multiSelect) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxDropDownList('selectItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else if (settings.checkboxes) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxDropDownList('checkItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        settings.selectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    };
                }
                break;
            case '27':
                break;
            case '28':
                break;
            case '29':
                break;              
            case '30':                
                break;
            //===============button================//                                                                                                                                                                                                
            case '31':
                settings.jqxType = 'jqxButton';
                break;
            case '32':
                settings.jqxType = 'jqxToggleButton';
                break;
            case '33':
                settings.jqxType = 'jqxRepeatButton';
                break;
            case '34':
                settings.jqxType = 'jqxLinkButton';
                break;
            case '35':
                settings.jqxType = 'jqxDropDownButton';
                break;
            case '36':
                settings.jqxType = 'jqxCheckBox';
                break;
            case '37':
                settings.jqxType = 'jqxRadioButton';
                break;
            case '38':
                settings.jqxType = 'jqxSwitchButton';
                break;
            case '39':
                settings.jqxType = 'jqxButtonGroup';
                break;
            case '40':
                break;
            //===============tree================//                                                                                                                                                                      
            case '41':
                settings.jqxType = 'jqxTree';                                
                if (settings.source) {
                    source = settings.source;
                    if(source.url){ 
                        settings.source = [];                                               
                        window.setTimeout(function () {
                            RMS.Ajax({
                                url: source.url,
                                data:{action: source.action},
                                type: 'post',
                                success: function (data) {                                    
                                    if (data) {
                                        data = new RMS.CCSV2JSON(data).toJson();
                                        if (data && data[1]) {
                                            data = RMS.pub.convert2TreeData(data[1], 'items');
                                            $(settings.id).jqxTree({ source: data });
                                        }
                                    }
                                }
                            });                                                                
                        }, 10);
                    }
                }
                break;
            case '42': 
                settings.jqxType = 'jqxTree';
                if (settings.source) {
                    source = settings.source;
                    if(source.url){ 
                        settings.source = [];                                               
                        window.setTimeout(function () {
                            RMS.Ajax({
                                url: source.url,
                                data: {action: source.action },
                                type: 'post',
                                success: function (data) {                                    
                                    if (data) {
                                        data = new RMS.CCSV2JSON(data).toJson();
                                        if (data && data[1]) {
                                            data = RMS.pub.convert2TreeData(data[1], 'items');
                                            settings.callback({ source: data });                                            
                                        }
                                    }
                                }
                            });                                                                
                        }, 10);
                    }                    
                    settings.callback = function(data){
                        if(data && data.source){
                            var $tree = $(settings.id);
                            $tree.jqxTree(data);                            
                            $tree.on('expand', function (event) {
                                var label = $tree.jqxTree('getItem', event.args.element).label,
                                    $element = $(event.args.element),
                                    loader = false,
                                    loaderItem = null,
                                    $children = $element.find('ul:first').children(),
                                    item;
                                $children.each(function () {
                                    item = $tree.jqxTree('getItem', this);
                                    if (item && item.label == 'Loading...') {
                                        loaderItem = item;
                                        loader = true;
                                        return false
                                    };
                                });
                                if (loader) {
                                    RMS.Ajax({
                                        url: source.url,
                                        data: {action: source.action },
                                        type: 'post',
                                        success: function (data) {                                    
                                            if (data) {
                                                data = new RMS.CCSV2JSON(data).toJson();
                                                if (data && data[1]) {
                                                    data = RMS.pub.convert2TreeData(data[1], 'items');
                                                    $tree.jqxTree('addTo', data, $element[0]);
                                                    $tree.jqxTree('removeItem', loaderItem.element);                                           
                                                }
                                            }
                                        }
                                    });                                      
                                }
                            });    
                        }
                    };
                }
                break;
            case '43': 
                settings.jqxType = 'jqxTree';
                break;
            case '44': 
                settings.jqxType = 'jqxTree';
                break;
            case '45':
                settings.jqxType = 'jqxTree';
                break;
            //===============menu================//                                                                                                                                                                 
            case '46':
                settings.jqxType = 'jqxMenu';
                break;
            case '47': //vertical
                settings.jqxType = 'jqxMenu';
                break;
            case '48': //direction
                settings.jqxType = 'jqxMenu';
                break;
            case '49': //column
                settings.jqxType = 'jqxMenu';
                break;
            case '50': //center
                settings.jqxType = 'jqxMenu';
                break;
            //===============tab================//                                                                                                                                                                       
            case '51':
                settings.jqxType = 'jqxTabs';
                break;
            case '52':
                settings.jqxType = 'jqxTabs';
                break;
            case '53':
                settings.jqxType = 'jqxTabs';
                break;
            case '54':
                settings.jqxType = 'jqxTabs';
                break;
            case '55':
                settings.jqxType = 'jqxTabs';
                break;
            //===============utilities================//                                                                                                                                                                         
            case '56':
                settings.jqxType = 'jqxWindow';
                break;
            case '57':
                settings.jqxType = 'jqxWindow';
                break;

            case '58':
                settings.jqxType = 'jqxDocking';
                break;
            case '59':
                settings.jqxType = 'jqxDocking';
                break;

            case '60':
                settings.jqxType = 'jqxExpander';
                break;
            case '61':
                settings.jqxType = 'jqxExpander';
                break;

            case '62':
                settings.jqxType = 'jqxSlider';
                break;
            case '63':
                settings.jqxType = 'jqxSlider';
                break;

            case '64':
                settings.jqxType = 'jqxNavigationBar';
                break;
            case '65':
                settings.jqxType = 'jqxNavigationBar';
                break;

            case '66':
                settings.jqxType = 'jqxRangeSelector';
                break;
            case '67':
                settings.jqxType = 'jqxRangeSelector';
                break;

            case '68':
                settings.jqxType = 'jqxPanel';
                break;

            case '69':
                settings.jqxType = 'jqxDockPanel';
                break;

            case '70':
                settings.jqxType = 'jqxDragDrop';
                break;

            case '71':
                settings.jqxType = 'jqxValidator';
                break;

            case '72':
                settings.jqxType = 'jqxSplitter';
                break;
            case '73':
                settings.jqxType = 'jqxSplitter';
                break;

            case '74':
                settings.jqxType = 'jqxRating';
                break;

            case '75':
                settings.jqxType = 'jqxProgressBar';
                break;

            case '76':
                settings.jqxType = 'jqxTreeMap';
                break;
            case '77':
                settings.jqxType = 'jqxTreeMap';
                break;
            case '78':
                settings.jqxType = 'jqxTreeMap';
                break;
            case '79':
                settings.jqxType = 'jqxTreeMap';
                break;
            case '80':
                settings.jqxType = 'jqxTreeMap';
                break;
            //===============grid================//                                                                                                                                                             
            case '81':
                settings.jqxType = 'jqxGrid';
                break;
            case '82':
                break;
            case '83':
                break;
            case '84':
                break;
            case '85':
                break;
            case '86':
                break;
            case '87':
                break;
            case '88':
                break;
            case '89':
                break;
            case '90':
                break;
            //===============chart================//                                                                                                                                                              
            case '91':
                settings.jqxType = 'jqxChart';
                break;
            case '92':
                break;
            case '93':
                break;
            case '94':
                break;
            case '95':
                break;
            case '96':
                break;
            case '97':
                break;
            case '98':
                break;
            case '99':
                break;
            case '100':
                break;
            //===============datatable================//                                                                                                                                                               
            case '101':
                settings.jqxType = 'jqxDataTable';
                break;
            case '102':
                break;
            case '103':
                break;
            case '104':
                break;
            case '105':
                break;
            case '106':
                break;
            case '107':
                break;
            case '108':
                break;
            case '109':
                break;
            case '110':
                break;
            //===============TreeGrid================//                                                                                                                                                                 
            case '111':
                settings.jqxType = 'jqxTreeGrid';
                break;
            case '112':
                break;
            case '113':
                break;
            case '114':
                break;
            case '115':
                break;
            case '116':
                break;
            case '117':
                break;
            case '118':
                break;
            case '119':
                break;
            case '120':
                break;

            //===============Listbox================//                                                                                                                                                                 
            case '121':
                settings.jqxType = 'jqxListBox';
                if (settings.source) {
                    source = settings.source;
                    if (typeof settings.valueMember == 'undefined') {
                        settings.valueMember = "ID";
                        settings.displayMember = "Name";
                    }
                    if(source.url){
                        settings.source = new $.jqx.dataAdapter(source, {
                            loadServerData: function (serverdata, source, callback) {
                                RMS.Ajax({
                                    url: source.url,
                                    type: 'post',
                                    success: function (data) {                                        
                                        if (data) {
                                            data = new RMS.CCSV2JSON(data).toJson();
                                            if (data && data[1]) {
                                                data = data[1];
                                            }
                                        }
                                        callback({ records: data });
                                    }
                                });
                            },
                            loadComplete: function (data) {
                                //waiting control init success
                                window.setTimeout(function () {
                                    settings.callback(data);
                                }, 10);
                            }
                        });    
                    }                       

                    settings.callback = function (data) {
                        if (data.records) {
                            if (settings.multiple) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('selectItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else if (settings.checkboxes) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('checkItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        settings.selectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    };
                }
                break;
            case '122':
                settings.jqxType = 'jqxListBox';
                if (settings.source) {
                    source = settings.source;
                    if (typeof settings.valueMember == 'undefined') {
                        settings.valueMember = "ID";
                        settings.displayMember = "Name";
                    }
                    if(source.url){
                        settings.source = new $.jqx.dataAdapter(source, {
                            loadServerData: function (serverdata, source, callback) {
                                RMS.Ajax({
                                    url: source.url,
                                    type: 'post',
                                    success: function (data) {                                        
                                        if (data) {
                                            data = new RMS.CCSV2JSON(data).toJson();
                                            if (data && data[1]) {
                                                data = data[1];
                                            }
                                        }
                                        callback({ records: data });
                                    }
                                });
                            },
                            loadComplete: function (data) {
                                //waiting control init success
                                window.setTimeout(function () {
                                    settings.callback(data);
                                }, 10);
                            }
                        });    
                    }                       

                    settings.callback = function (data) {
                        if (data.records) {
                            if (settings.multiple) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('selectItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else if (settings.checkboxes) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('checkItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        settings.selectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    };
                }
                settings.allowDrop = true;
                settings.allowDrag = true;
                settings.dragStart = function (item) {
                    return true;
                };
                settings.renderer = function (index, label, value) {                    
                    return label;
                };
                break;
            case '123':
                settings.jqxType = 'jqxListBox';
                if (settings.source) {
                    source = settings.source;
                    if (typeof settings.valueMember == 'undefined') {
                        settings.valueMember = "ID";
                        settings.displayMember = "Name";
                    }
                    if(source.url){
                        settings.source = new $.jqx.dataAdapter(source, {
                            loadServerData: function (serverdata, source, callback) {
                                RMS.Ajax({
                                    url: source.url,
                                    type: 'post',
                                    success: function (data) {                                        
                                        if (data) {
                                            data = new RMS.CCSV2JSON(data).toJson();
                                            if (data && data[1]) {
                                                data = data[1];
                                            }
                                        }
                                        callback({ records: data });
                                    }
                                });
                            },
                            loadComplete: function (data) {
                                //waiting control init success
                                window.setTimeout(function () {
                                    settings.callback(data);
                                }, 10);
                            }
                        });    
                    }                       

                    settings.callback = function (data) {
                        if (data.records) {
                            if (settings.multiple) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('selectItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else if (settings.checkboxes) {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        $(settings.id).jqxComboBox('checkItem', data.records[i][settings.valueMember]);
                                    }
                                }
                            }
                            else {
                                for (i = 0; i < data.records.length; i++) {
                                    if (RMS.pub.convertBool(data.records[i].DefaultValue)) {
                                        settings.selectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    };
                    settings.multipleextended = true;
                    settings.rendered = function () {
                        $(settings.id).jqxListBox('focus');
                    }
                }
                break;
            case '124':
                settings.jqxType = 'jqxListBox';
                break;
            case '125':
                settings.jqxType = 'jqxListBox';
                break;
            case '126':
                settings.jqxType = 'jqxListBox';
                break;
            case '127':
                settings.jqxType = 'jqxListBox';
                break;
            case '128':
                settings.jqxType = 'jqxListBox';
                break;
            case '129':
                settings.jqxType = 'jqxListBox';
                break;
            case '130':
                settings.jqxType = 'jqxListBox';
                break;
            default:
                settings.jqxType = 'jqxInput';
                break;
        }
        return settings;
    };

    RMS.CControl = Control;
})(RMS);
//=====================================================================================================
//Overwrite jqWidget custom class
//=====================================================================================================
$.fn.factory = function (action) {
    var output,
        userSettings,
        $this = this,
        instance = $this.data('rms-ctrl');

    // Init case
    if (typeof action !== 'string') {
        userSettings = action || {};
        if (instance) {
            instance.updateSettings(userSettings);
        }
        else {
            instance = new jqxControl.Core($this, userSettings);
            $this.data('rms-ctrl', instance);
            instance.init();
        }
        return $this;
    }
    // Action case
    else {
        if (instance) {
            output = instance.execute.apply(instance, arguments);
        }
        return output;
    }
};
//=====================================================================================================
//JQWidgets custom class
//=====================================================================================================
var jqxControl = {
    Message: {
        NotSupport: 'jqWidgets do not provide action: '
    }
};
jqxControl.Core = function ($ctrl, settings) {
    this.defaults = {};
    this.jqxType = null;
    this.$ctrl = $ctrl;

    //extend properties
    $.extend(true, this.defaults, settings);

    //init function
    this.init = function () {
        this.jqxType = this.defaults.jqxType;
        if (typeof this.jqxType != 'undefined' && typeof this.$ctrl[this.jqxType] != 'undefined') {
            delete this.defaults.jqxType;
            this.$ctrl[this.jqxType](this.defaults);
        }
    };

    //update settings
    this.updateSettings = function (settings) {
        //extend properties
        $.extend(true, this.defaults, settings);
        this.$ctrl[this.jqxType](this.defaults);
    };

    this.getInstance = function () {
        return this;
    };
    this.execute = function () {
        var instance = this.$ctrl[this.jqxType].apply(this.$ctrl, ['getInstance']),
            action = arguments[0],
            args = [];
        if (arguments.length > 1) {
            for (i = 1, ilen = arguments.length; i < ilen; i++) {
                args.push(arguments[i]);
            }
        }

        if (typeof instance[action] != 'undefined') {
            return instance[action].apply(instance, args);
        }
        else {
            throw new Error(this.Message.NotSupport + action);
        }
    };
};
//=====================================================================================================
//END
//=====================================================================================================